package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @descriptions: ...
 * @author: 唐杰
 * @date: 2019/11/20  15:30
 * @version: 1.0
 */
@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionDao permissionDao;

    /*
     * 根据id查询权限数据
     * */
    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }
    /*
    * 分页查询所有数据
    * */
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();//当前页码
        Integer pageSize = queryPageBean.getPageSize();//每页查询数据的长度
        String queryString = queryPageBean.getQueryString();//查询条件
        //完成分页查询，基于mybatis框架提供的分页助手插件完成
        PageHelper.startPage(currentPage,pageSize);
        //select * from t_checkitem limit 0,10
        Page<Permission> page = permissionDao.selectByCondition(queryString);
        long total = page.getTotal();
        List<Permission> rows = page.getResult();
        return new PageResult(total,rows);
    }

    /*
    * 查询所有权限数据
    * */
    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }

    /*
    * 新增权限数据
    * */
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    /*
    * 编辑权限数据
    * */
    @Override
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }

    /*
    * 根据id删除权限数据
    * */
    @Override
    public void delete(Integer id) {
        permissionDao.deleteById(id);
    }


}
